package cn.chuanw.wx.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import cn.chuanw.wx.annotation.RequiresPermissionsDesc;
import cn.chuanw.core.util.RandomNumberUtil;
import cn.chuanw.core.util.ResponseUtil;
import cn.chuanw.db.domain.WRenovationRecord;
import cn.chuanw.db.service.WRenovationRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/renovationRecord")
@Validated
public class WRenovationRecordController {
    private final Log logger = LogFactory.getLog(WRenovationRecordController.class);

    @Autowired
    private WRenovationRecordService wRenovationRecordService;

    @RequiresPermissions("admin:renovationRecord:list")
    @RequiresPermissionsDesc(menu = {"公寓管理", "装修费用信息"}, button = "查询")
    @GetMapping("/list")
    public Object list(
    		String houseId,
    		Integer costType,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit) {
        List<WRenovationRecord> wRenovationRecord = wRenovationRecordService.querySelective(houseId,costType, page, limit);
        return ResponseUtil.okList(wRenovationRecord);
    }


    @RequiresPermissions("admin:renovationRecord:add")
    @RequiresPermissionsDesc(menu = {"公寓管理", "装修费用信息"}, button = "新增")
    @PostMapping("/add")
    public Object add(@RequestBody WRenovationRecord wRenovationRecord) {
    	wRenovationRecord.setId(RandomNumberUtil.getStringRandom(12));
    	wRenovationRecordService.addWHouseInfo(wRenovationRecord);
        return ResponseUtil.ok(wRenovationRecord);
    }


    @RequiresPermissions("admin:renovationRecord:update")
    @RequiresPermissionsDesc(menu = {"公寓管理", "装修费用信息"}, button = "修改")
    @PostMapping("/update")
    public Object update(@RequestBody WRenovationRecord wRenovationRecord) {
    	wRenovationRecordService.updateById(wRenovationRecord);
        return ResponseUtil.ok(wRenovationRecord);
    }
}
